package com.jsbs.iam.job.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.jsbs.iam.common.core.utils.ExceptionUtil;
import java.time.LocalDateTime;

import static com.xxl.job.core.biz.model.ReturnT.FAIL_CODE;

/**
 * 说明：
 * 1、xxl-job有自己单独的执行日志，日志路径为${xxl.job.executor.logpath}
 * 2、如果希望日志被打印到xxl-job自己的日志文件中，需要使用XxlJobLogger.log
 */
@Component
public class SampleJob {

    private static final Logger LOGGER = LoggerFactory.getLogger(SampleJob.class);

    @XxlJob("demoJobHandler")
    public ReturnT<String> demoJobHandler(String param) {
        LOGGER.info("XXX任务开始:" + LocalDateTime.now());
        try{
            LOGGER.info("这里做一些业务操作");
        }catch (RuntimeException e){
            LOGGER.error(e.toString(), e);
            return new ReturnT<>(FAIL_CODE, ExceptionUtil.getDetail(e));
        }
        LOGGER.info("XXX任务结束:" + LocalDateTime.now());
        return ReturnT.SUCCESS;
    }

}
